import plugin from '../../lib/plugins/plugin.js'
import { segment } from "oicq";
import fetch from 'node-fetch'
import cfg from '../../lib/config/config.js'
import schedule from "node-schedule";
import moment from "moment";

let GayCD = {};

export class example extends plugin {
  constructor () {
    super({
      /** 功能名称 */
      name: '同归于尽',
      /** 功能描述 */
      dsc: '简单开发示例',
      /** https://oicqjs.github.io/oicq/#events */
      event: 'message',
      /** 优先级，数字越小等级越高 */
      priority: 5000,
      rule: [
        {
          /** 命令正则匹配 */
          reg: '^同归于尽$',
          /** 执行方法 */
          fnc: 'tgyj'
        },
        {
          /** 命令正则匹配 */
          reg: '^重生$',
          /** 执行方法 */
          fnc: 'chongsheng'
        }
      ]
    })
  }

 
  async tgyj(e) {
      
     let id = e.group_id + e.user_id
   
    if(GayCD[id]){
        e.reply("该命令有三分钟冷却时间!");
        return true;
    }
    
    
     
   
   
   let qq2 =  e.user_id
  let qq = null
  
    for(let msg of e.message){
     
       if(msg.type =='at'){
           qq = msg.qq
           break
     }
    }
    
    if(qq == null){
       e.reply("未识别成功,请艾特对方使用",true)
        return true
    }
    
    var num = Math.random();
  num = Math.ceil(num * 999);
 var nums = num*0.30
 var numss = num + nums
 
 
 
 
 var num2 = Math.random();
  num2 = Math.ceil(num2 * 999);

if(numss > num2){
 e.reply(`由于你是发起者,所以你将加伤30％,因此你受到${numss}(${num}+${nums})点伤害,对方受到${num2}点伤害,恭喜你惩罚加倍！`,true)
  e.group.muteMember(qq2,120);
  e.group.muteMember(qq,60);
}else if(numss < num2){
    e.reply(`由于你是发起者,所以你将加伤30％,因此你受到${numss}(${num}+${nums})点伤害,对方受到${num2}点伤害,恭喜你惩罚减少！`,true)
  e.group.muteMember(qq2,60);
  e.group.muteMember(qq,120);
}else{
     e.reply(`由于你是发起者,所以你将加伤30％,因此你受到${numss}(${num}+${nums})点伤害,对方受到`+num2+`点伤害,恭喜你们惩罚一样！`,true)
  e.group.muteMember(qq2,60);
  e.group.muteMember(qq,60);
}

    GayCD[id] = true;

    GayCD[id] = setTimeout(() => {
        if (GayCD[id]) {
            delete GayCD[id];
        }
    }, 180000);
  //执行的逻辑功能
 
  return true; //返回true 阻挡消息不再往下
  }
  
  async chongsheng(e){
      let qq = null
      
       for(let msg of e.message){
     
       if(msg.type =='at'){
           qq = msg.qq
           break
      
       }
    }
    
    if(qq == null){
       e.reply("未识别成功,请艾特对方使用",true)
        return true
    }
    
       e.group.muteMember(qq,0);
       
     return true;
  }
}
